public class Solution {
    public int firstUniqChar(String s) {
        if(s.length() == 0) {
            return -1;
        }
        LinkedHashMap<Character, Integer> map = new LinkedHashMap<>();
        for(int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            Integer t = map.putIfAbsent(c, 1);
            if(t != null) {
                map.put(c, t + 1);
            }
        }

        for(Map.Entry<Character, Integer> entry : map.entrySet()) {
            if(entry.getValue() == 1) {
                return s.indexOf(entry.getKey());
            }
        }
        return -1;
    }
}